package com.hyt.it.ogt.pj.data.service.pj.impl;

import java.math.BigDecimal;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hyt.core.base.BaseServiceImpl;
import com.hyt.core.util.FastJsonUtil;
import com.hyt.it.ogt.pj.data.asynchronous.PjIncrementDataDistribution;
import com.hyt.it.ogt.pj.data.common.Constants;
import com.hyt.it.ogt.pj.data.common.ResponseCode;
import com.hyt.it.ogt.pj.data.enums.CommonEnums;
import com.hyt.it.ogt.pj.data.exception.MarkException;
import com.hyt.it.ogt.pj.data.mapper.pj.ProjectMapper;
import com.hyt.it.ogt.pj.data.model.dto.StudentExtendDTO;
import com.hyt.it.ogt.pj.data.model.entity.pj.Config;
import com.hyt.it.ogt.pj.data.model.entity.pj.ItemScore;
import com.hyt.it.ogt.pj.data.model.entity.pj.Paper;
import com.hyt.it.ogt.pj.data.model.entity.pj.PaperItem;
import com.hyt.it.ogt.pj.data.model.entity.pj.Piece;
import com.hyt.it.ogt.pj.data.model.entity.pj.PieceItem;
import com.hyt.it.ogt.pj.data.model.entity.pj.PieceScore;
import com.hyt.it.ogt.pj.data.model.entity.pj.Project;
import com.hyt.it.ogt.pj.data.model.entity.pj.Student;
import com.hyt.it.ogt.pj.data.model.entity.pj.StudentAnswer;
import com.hyt.it.ogt.pj.data.model.entity.pj.Subject;
import com.hyt.it.ogt.pj.data.model.entity.pj.Task;
import com.hyt.it.ogt.pj.data.model.vo.kw.ProjectVO;
import com.hyt.it.ogt.pj.data.model.vo.pj.ObjectiveScoreVO;
import com.hyt.it.ogt.pj.data.model.vo.pj.PaperDataVO;
import com.hyt.it.ogt.pj.data.model.vo.pj.StudentAnswerVO;
import com.hyt.it.ogt.pj.data.model.vo.pj.SubjectScore;
import com.hyt.it.ogt.pj.data.service.kw.IExamCandidateService;
import com.hyt.it.ogt.pj.data.service.kw.IExamPaperService;
import com.hyt.it.ogt.pj.data.service.pj.ICommonAutomaticAllocationService;
import com.hyt.it.ogt.pj.data.service.pj.IConfigService;
import com.hyt.it.ogt.pj.data.service.pj.IExamExpertService;
import com.hyt.it.ogt.pj.data.service.pj.IItemScoreService;
import com.hyt.it.ogt.pj.data.service.pj.IPaperItemService;
import com.hyt.it.ogt.pj.data.service.pj.IPaperService;
import com.hyt.it.ogt.pj.data.service.pj.IPieceItemService;
import com.hyt.it.ogt.pj.data.service.pj.IPieceScoreService;
import com.hyt.it.ogt.pj.data.service.pj.IPieceService;
import com.hyt.it.ogt.pj.data.service.pj.IProjectService;
import com.hyt.it.ogt.pj.data.service.pj.IStudentAnswerService;
import com.hyt.it.ogt.pj.data.service.pj.IStudentService;
import com.hyt.it.ogt.pj.data.service.pj.ISubjectScoreService;
import com.hyt.it.ogt.pj.data.service.pj.ISubjectService;
import com.hyt.it.ogt.pj.data.service.pj.ITaskService;
import com.hyt.it.ogt.pj.data.utils.DateTimeUtil;
import com.hyt.it.ogt.pj.data.utils.ExecutorPoolUtil;
import com.hyt.it.ogt.pj.data.utils.MathUtils;
import com.hyt.it.ogt.pj.data.utils.UUIDUtils;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;

/**
 * <p>
 * 评卷项目表 服务实现类
 * </p>
 *
 * @author liuqi
 * @date 2022-06-02
 */
@Service
public class ProjectServiceImpl extends BaseServiceImpl<ProjectMapper, Project> implements IProjectService {

	protected Logger logger = LoggerFactory.getLogger(this.getClass());

	/*************************************pj*********************************************/

	@Resource
	private IConfigService iConfigService;

	@Resource
	private ISubjectService iSubjectService;

	@Resource
	private IPaperService iPaperService;

	@Autowired
	private IPaperItemService iPaperItemService;

	@Resource
	private IStudentService iStudentService;

	@Resource
	private IStudentAnswerService iStudentAnswerService;

	@Resource
	private IPieceService pieceService;

	@Resource
	private IPieceScoreService pieceScoreService;

	@Resource
	private IPieceItemService pieceItemService;

	@Resource
	private ISubjectScoreService iSubjectScoreService;

	@Resource
	private ITaskService taskService;

	@Resource
	private ICommonAutomaticAllocationService commonAutomaticAllocationService;

	@Autowired
	private PjIncrementDataDistribution pjIncrementDataDistribution;

	@Resource
	private IItemScoreService iItemScoreService;

	/**************************************kw *********************************************/

	@Resource
	private IExamCandidateService iExamCandidateService;

	@Resource
	private IExamPaperService iExamPaperService;
	
	@Resource
	private IExamExpertService examExpertService;

	@Override
	public void initProjectForTask(String projectId, String officeId) throws Exception {
		// 1.保存评卷项目信息
		this.saveProject(projectId, officeId);
		// 2.初始化评卷参数
		iConfigService.initMarkParam(projectId);
	}

	@Override
	public void addProjectStudentForTask(String projectId, String officeId, String admissionNum) throws Exception {
		// 0.重复的考生推送先把上一次撤销
		List<Student> studentList = iStudentService.lambdaQuery().eq(Student::getProjectId, projectId).eq(Student::getAdmissionNum, admissionNum).list();
		if(CollectionUtil.isNotEmpty(studentList)) {
			cancelCandidateTask(projectId, admissionNum);
		}
		// 1. 考务查询科目信息
		List<Subject> subjectsTemp = iExamCandidateService.getCandidateSubject(projectId, admissionNum);
		if (CollectionUtils.isEmpty(subjectsTemp)) {
			throw new MarkException(ResponseCode.INIT_PROJECT_NO_SUBJECT.toString());
		}
		// 2.考务查询试卷信息
		List<PaperDataVO> papers = iExamPaperService.getPaperBySubjectId(projectId, projectId, admissionNum);
		if (CollectionUtils.isEmpty(papers)) {
			throw new MarkException(ResponseCode.INIT_PROJECT_NO_PAPER.toString());
		}
		
		// 过滤掉没有试卷的科目信息
		List<Subject> subjects = delNoPaperItemsPapers(papers, subjectsTemp);
	
		// 3.考务查询考生信息
		List<StudentExtendDTO> studentExtendDTOs = iExamCandidateService.getCandidateInfo(projectId, admissionNum);
		
		// 4. 考务查询考生答案
		List<StudentAnswerVO> studentAnswerVOs = iExamCandidateService.getCandidateAnswer(projectId, admissionNum);
		if (CollectionUtils.isEmpty(studentAnswerVOs)) {
			throw new MarkException(ResponseCode.INIT_PROJECT_NO_STUDENT_ANSWER.toString());
		}
		
		// 5. 考务查询客观题分数
		List<ObjectiveScoreVO> objectiveScoreVOs = iExamCandidateService.getObjectiveScore(projectId, admissionNum);
		
		// 6. 评卷保存科目信息
		iSubjectService.saveSubject(projectId, subjects);
		
		// 7. 评卷保存试卷信息
		iPaperService.savePaper(projectId, papers);
		
		// 8. 评卷保存考生信息
		iStudentService.saveStudent(projectId, studentExtendDTOs);
		
		// 9. 评卷保存考生答案
		iStudentAnswerService.saveStudentAnswer(projectId, studentAnswerVOs);
		
		// 10. 评卷保存科目客观题分数
		iSubjectScoreService.saveObjectiveScore(projectId, objectiveScoreVOs, subjects);
		
		// 11. 评卷初始化评卷块
		initMarkConstruct(projectId, officeId, admissionNum, studentExtendDTOs);
		
		// 12.考务标记考生
		iExamCandidateService.markCandidate(projectId, admissionNum);
		
		// 13. 自动分配评卷任务
		incrementDataDistribution(projectId);
	}

	/**
	 * 重复的考生推送先把上一次撤销
	 * @param projectId
	 * @param admissionNum
	 */
	private void cancelCandidateTask(String projectId, String admissionNum) {
	    
	    //1、减少科目表中的实考人数(pj_subject)
        iStudentService.reduceExamNum(projectId, admissionNum);

        //2、删除考生表中对应需要撤销评卷的考生(pj_student)
        iStudentService.remove(new LambdaQueryWrapper<Student>().eq(Student::getProjectId, projectId).eq(Student::getAdmissionNum, admissionNum));

        //3、考生答案表中删除对应需要撤销评卷的考生答案(pj_student_answer)
        iStudentAnswerService.remove(new LambdaQueryWrapper<StudentAnswer>().eq(StudentAnswer::getProjectId, projectId).eq(StudentAnswer::getAdmissionNum, admissionNum));

        //4、考生客观分表中删除对应需要撤销评卷的考生客观分(pj_subject_score)
        iSubjectScoreService.remove(new LambdaQueryWrapper<SubjectScore>().eq(SubjectScore::getProjectId, projectId).eq(SubjectScore::getAdmissionNum, admissionNum));
        
        
		List<Task> taskList = taskService.lambdaQuery().eq(Task::getProjectId, projectId).eq(Task::getAdmissionNum, admissionNum).list();
		if(CollectionUtil.isEmpty(taskList)){
		    logger.info(">>>>>>>>>>> 撤销交卷查询task.size is null :{},{}", admissionNum, projectId);
			return;
		}

		logger.info(">>>>>>>>>>> 撤销交卷：admissionNum:{},projectId:{}", admissionNum, projectId);
		List<String> taskIdList = taskList.stream().map(item -> item.getId()).collect(Collectors.toList());

		
        // 5、查询需要被删除的试题id
        List<String> itemIdList = iItemScoreService.lambdaQuery().eq(ItemScore::getEncodeId, admissionNum)
            .in(ItemScore::getTaskId, taskIdList).list().stream().map(ItemScore::getItemId)
            .collect(Collectors.toList());

        // 6、删除考生小题分数(pj_item_score)
        iItemScoreService.remove(new LambdaQueryWrapper<ItemScore>().eq(ItemScore::getEncodeId, admissionNum)
            .in(ItemScore::getTaskId, taskIdList)
            .in(CollectionUtil.isNotEmpty(itemIdList), ItemScore::getItemId, itemIdList));

        // 7、删除pieceScore
        pieceScoreService.remove(new LambdaQueryWrapper<PieceScore>().eq(PieceScore::getEncodeId, admissionNum)
            .in(PieceScore::getTaskId, taskIdList));

        // 8、通过id删除评卷任务(pj_task)
        taskService.remove(new LambdaQueryWrapper<Task>().in(Task::getId, taskIdList));
	}

	/**
	 * 移除掉没有主观题的试卷
	 * @param paperTemps
	 * @param subjects
	 * @return
	 */
	private List<Subject> delNoPaperItemsPapers(List<PaperDataVO> paperTemps, List<Subject> subjects) {
		List<String> unRemovesubjectIds = new ArrayList<String>();
		for (Iterator<PaperDataVO> iterator = paperTemps.iterator(); iterator.hasNext();) {
			PaperDataVO paperDataVO = iterator.next();
			unRemovesubjectIds.add(paperDataVO.getSubjectId());
		}
		if (!CollectionUtils.isEmpty(unRemovesubjectIds)) {
			for (Iterator<Subject> iterator = subjects.iterator(); iterator.hasNext();) {
				Subject subject = iterator.next();
				if (!unRemovesubjectIds.contains(subject.getSubjectId())) {
					iterator.remove();
				}
			}
		}
		return subjects;
	}

	private void incrementDataDistribution(String pjProjectId) {
		// 将评分数据同步到成绩系统
		pjIncrementDataDistribution.setPjProjectId(pjProjectId);
		pjIncrementDataDistribution.setiCommonAutomaticAllocationService(commonAutomaticAllocationService);
		// 异步形成执行批处理操作，可能数据量比较大
		ExecutorPoolUtil.getExecutorService().execute(pjIncrementDataDistribution);
	}

	/**
	 * 保存评卷项目信息
	 *
	 * @param projectId
	 */
	private void saveProject(String projectId, String officeId) {
		// 1.初始化项目
		if (projectId == null) {
			throw new MarkException(ResponseCode.INIT_PROJECTID_NULL.toString());
		}
		Project project = this.getById(projectId);
		if (project != null && project.getIsInit()) {
			// 1.1已經初始化過了
			throw new MarkException(ResponseCode.INIT_PROJECT_EXIST_ERROR.toString());
		}
		// 1.2直接查数据库获取项目相关信息，并插入数据库
		project = this.getProjectById(projectId);
		project.setIsInit(true);
		project.setOfficeId(officeId);
		project.setVersion(CommonEnums.PROJECT_VERSION_1.getCode());
		// 如果是无考场数据
		if (CommonEnums.EXAM_CLASSFICATION_0.getCode().equals(project.getExamClassfication())) {
			project.setTaskName((project.getProjectName()));
			project.setTaskId(project.getId());
			project.setTaskBeginDate(project.getBeginDate());
			project.setTaskEndDate(project.getEndDate());
		}
		this.save(project);
	}

	/**
	 * 从kw库查项目信息(原来是通过kwClient查询)
	 *
	 * @param projectId
	 */
	private Project getProjectById(String projectId) {
		ProjectVO kwProjectInfo = iExamPaperService.getProjectInfo(projectId);
		Project pjProject = new Project();
		BeanUtils.copyProperties(kwProjectInfo, pjProject);
		pjProject.setBeginDate(DateTimeUtil.parseDate(kwProjectInfo.getBeginDate()));
		pjProject.setEndDate(DateTimeUtil.parseDate(kwProjectInfo.getEndDate()));
		pjProject.setTaskBeginDate(DateTimeUtil.asDate(kwProjectInfo.getTaskBeginDate()));
		pjProject.setTaskEndDate(DateTimeUtil.asDate(kwProjectInfo.getTaskEndDate()));
		return pjProject;
	}

	/**
	 * 初始化评卷结构
	 *
	 * @param projectId
	 *            评卷项目id
	 * @param officeId
	 *            用户id
	 * @param admission
	 *            准考证号
	 */
	private void initMarkConstruct(String projectId, String officeId, String admission, List<StudentExtendDTO> studentExtendDTO) {
		// 1.读取参数查看评卷模式，默认为整卷模式
		Config config = iConfigService.selectByLabel(projectId, Constants.MARK_MODEL);
		// 如果是整卷评卷
		if (config != null && "A".equals(config.getValue())) {
			// 整卷评卷
			markPaperIncrment(projectId, officeId, admission, studentExtendDTO);
		} else if (config != null && "I".equals(config.getValue())) {
			// 按题评卷
		}
	}

	/**
	 * 增量任务下初始化评卷结构
	 *
	 * @param projectId
	 *            评卷项目id
	 * @param officeId
	 *            用户id
	 * @param admission
	 *            准考证号
	 */
	private void markPaperIncrment(String projectId, String officeId, String admission, List<StudentExtendDTO> studentExtendDTOS) {
		// 组装task需要的数据
		Map<String, StudentExtendDTO> studentExtendMap = new HashMap<>();
		for (StudentExtendDTO item : studentExtendDTOS) {
			StringBuilder key = new StringBuilder();
			key.append(item.getProjectId());
			key.append(item.getSubjectId());
			key.append(item.getAdmissionNum());
			studentExtendMap.put(key.toString(), item);
		}
		List<Subject> subjects = iSubjectService.selectByProjectId(projectId);
		// 生成piece、pieceItem、task、teacherTaskInfo
		int subjectOrderNum = 0;
		Config scoreStep = iConfigService.selectByLabel(projectId, Constants.MARK_SCORE_STEP);
		Config reMarkLeng = iConfigService.selectByLabel(projectId, Constants.MARK_REMARK_LENGTH);
		Config minSubmitTime = iConfigService.selectByLabel(projectId, Constants.MARK_MIN_SUBMIT_TIME);
		logger.info("# markPaperIncrment subjects:{}" , FastJsonUtil.getBeanToJson(subjects));
		for (Subject subject : subjects) {
			String subjectId = subject.getSubjectId();
			List<Piece> existPieces = pieceService.selectByProjectIdSubjectId(projectId, subjectId);
			logger.info("# markPaperIncrment existPieces:{}" , FastJsonUtil.getBeanToJson(existPieces));
			String subjectPieceId = "";
			if (CollUtil.isEmpty(existPieces)) {
				subjectOrderNum++;
				Piece piece = new Piece();
				piece.setProjectId(projectId);
				piece.setSubjectId(subjectId);
				piece.setParentId("0");
				piece.setPieceName(subject.getSubjectName());
				piece.setPieceType(CommonEnums.PIECE_TYPE_1.getCode());// 科目评卷块
				piece.setOrderNum(subjectOrderNum);
				piece.setScoreStep(MathUtils.parseBigDecimal(scoreStep));
				pieceService.save(piece);
				subjectPieceId = piece.getId();
			} else {
				for (Piece piece : existPieces) {
					if (piece.getPieceType() == 1) {
						subjectPieceId = piece.getId();
					}
				}
			}
			List<Paper> papers = iPaperService.selectParersBySubjectId(projectId, subjectId);
			logger.info("# markPaperIncrment papers:{}" , FastJsonUtil.getBeanToJson(papers));
			int paperPieceOrderNum = 0;
			String lastPackageId = null;
			for (Paper paper : papers) {
				Piece existePaperPiece = pieceService.selectPaperPiece(projectId, subjectId, paper.getId());
				if (existePaperPiece == null) {
					if (paper.getPackageId() == null || !paper.getPackageId().equals(lastPackageId)) {
						// 同一个试卷包的paperPieceOrderNum相同
						paperPieceOrderNum++;
						lastPackageId = paper.getPackageId();
					}
					Piece existPiecePaper = pieceService.selectPaperPiece(projectId, subjectId, paper.getId());
					if (existPiecePaper == null) {
						if (paper.getPackageId() == null || !paper.getPackageId().equals(lastPackageId)) {
							// 同一个试卷包的paperPieceOrderNum相同
							paperPieceOrderNum++;
							lastPackageId = paper.getPackageId();
						}
						String paperId = paper.getId();
						Piece piecePaper = new Piece();
						piecePaper.setProjectId(projectId);
						piecePaper.setSubjectId(subjectId);
						piecePaper.setParentId(subjectPieceId);
						piecePaper.setPieceName(paper.getPaperName());
						piecePaper.setPackageId(paper.getPackageId());
						piecePaper.setPackageVersion(paper.getPackageVersion());
						piecePaper.setSort(paper.getSort());
						piecePaper.setPaperId(paperId);
						// 试卷评卷块
						piecePaper.setPieceType(CommonEnums.PIECE_TYPE_2.getCode());
						piecePaper.setRejudgeLength(MathUtils.parseInt(reMarkLeng));
						piecePaper.setMinSubmitTime(MathUtils.parseInt(minSubmitTime));
						piecePaper.setOrderNum(paperPieceOrderNum);
						piecePaper.setFullScore(paper.getSubjectiveScore());
						piecePaper.setScoreStep(MathUtils.parseBigDecimal(scoreStep));
						pieceService.save(piecePaper);
						List<PaperItem> paperItems = iPaperItemService.selectByPaperId(paperId);
						List<PieceItem> pieceItems = new ArrayList<>();
						for (PaperItem paperItem : paperItems) {
							PieceItem pieceItem = new PieceItem();
							pieceItem.setItemId(paperItem.getTopicId());
							pieceItem.setPieceId(piecePaper.getId());
							pieceItems.add(pieceItem);
						}
						pieceItemService.saveBatch(pieceItems);
					} 
//					else {
						// 更新一下piece表的packageId
//						existePaperPiece.setPackageVersion(paper.getPackageVersion());
//						pieceService.updateById(existePaperPiece);
//					}
				}
				incrementTask(projectId, subjectId, officeId, admission, studentExtendMap);
			}
		}
	}

	/**
	 * 生成增量评卷任务
	 *
	 * @param projectId
	 *            评卷项目id
	 * @param subjectId
	 *            评卷科目
	 * @param officeId
	 *            当前用户
	 * @param admissionNum
	 *            增量考生的准考证号
	 */
	private void incrementTask(String projectId, String subjectId, String officeId, String admissionNum, Map<String, StudentExtendDTO> studentExtendMap) {
		List<Task> existTasks = taskService.getStudentSubjectTask(projectId, subjectId, admissionNum);
		if (existTasks == null || existTasks.size() == 0) {
			List<Piece> pieces = pieceService.lambdaQuery().eq(Piece::getProjectId, projectId).eq(Piece::getSubjectId, subjectId).eq(Piece::getDelFlag, false).list();
			Student student = iStudentService.getByAdmissionNum(projectId, subjectId, admissionNum);
			// 由于外面循环的科目是全量的，AB卷可能会出现null的情况，return即可
			if (null == student) {
				return;
			}
			List<Task> tasks = new ArrayList<>();
			for (Piece piece : pieces) {
				boolean paperPiece = CommonEnums.PIECE_TYPE_2.getCode().equals(piece.getPieceType());
				boolean paperIdEqual = piece.getPackageId() == null && piece.getPaperId() != null && piece.getPaperId().equals(student.getPaperId());
				boolean packageIdEqual = piece.getPackageId() != null && piece.getPackageId().equals(student.getPackageId());
				if (paperPiece && (paperIdEqual || packageIdEqual)) {
					Task task = new Task();
					String taskId = UUIDUtils.genUUID();
					task.setId(taskId);
					task.setProjectId(projectId);
					task.setSubjectId(subjectId);
					task.setAdmissionNum(admissionNum);
					task.setEncodeId(admissionNum);
					task.setPieceId(piece.getId());
					task.setStage(Constants.MARK_STAGE);
					task.setStatus(0);
					// task 其他数据
					StringBuilder sb = new StringBuilder();
					sb.append(projectId);
					sb.append(subjectId);
					sb.append(admissionNum);
					StudentExtendDTO studentExtendDTO = studentExtendMap.get(sb.toString());
					extendTask(task, studentExtendDTO);
					tasks.add(task);
					pieceService.updateFinishStatus(projectId, subjectId, piece.getId(), false);
				}
			}
			taskService.saveBatch(tasks);
			if (CollUtil.isNotEmpty(tasks)) {
				iSubjectService.updateSubjectMarkStatus(projectId, subjectId, false);
			}
		}
	}

	/**
	 * 设置task相关考点考场等数据
	 * 
	 * @param task
	 * @param studentExtendDTO
	 */
	private void extendTask(Task task, StudentExtendDTO studentExtendDTO) {
		// 设置task里的值
		if (null != studentExtendDTO) {
			task.setPlaceId(studentExtendDTO.getPlaceId());
			task.setPlaceName(studentExtendDTO.getPlaceName());
			task.setRoomId(studentExtendDTO.getRoomId());
			task.setRoomName(studentExtendDTO.getRoomName());
			task.setSeatNo(studentExtendDTO.getSeatNo());
			// 考试开始时间
			if (null != studentExtendDTO.getExamBeginDate()) {
				task.setExamStartTime(Date.from(studentExtendDTO.getExamBeginDate().atZone(ZoneId.systemDefault()).toInstant()));
			}
			// 考试结束时间
			if (null != studentExtendDTO.getExamEndDate()) {
				task.setExamEndTime(Date.from(studentExtendDTO.getExamEndDate().atZone(ZoneId.systemDefault()).toInstant()));
			}
			// 考生答题时长
			if (null != studentExtendDTO.getSubjectUseTime()) {
				task.setAnswerTime(new BigDecimal(studentExtendDTO.getSubjectUseTime() / 1000));
			}
		}
		Project project = this.baseMapper.selectById(task.getProjectId());
		// 虚拟考场的设置批次名称和批次id
		if (null != project.getExamClassfication() && CommonEnums.EXAM_CLASSFICATION_1.getCode().equals(project.getExamClassfication())) {
			task.setBatchId(project.getId());
			task.setBatchName(project.getProjectName());
		}
	}

	@Override
	public void updateProjectForTask(String projectId, String officeId) {
		// 1.初始化项目
		if (projectId == null) {
			return;
		}
		Project project = this.getById(projectId);
		if (project != null) {
			// 1.2直接查数据库获取项目相关信息，并插入数据库
			Project kwProject = this.getProjectById(projectId);
			if (CommonEnums.EXAM_CLASSFICATION_0.getCode().equals(project.getExamClassfication())) {
				project.setProjectName(kwProject.getProjectName());
				project.setTaskId(kwProject.getId());
				project.setTaskName(kwProject.getProjectName());
				project.setTaskBeginDate(kwProject.getBeginDate());
				project.setTaskEndDate(kwProject.getEndDate());
			}
			this.baseMapper.updateById(project);
		}
	}
}
